require "base/internal/ui/reflexcore"

local time = 0;

MgHUD_Buffs = 
{
    userData = {}
}
registerWidget("MgHUD_Buffs");

local function drawBuff(x, y, icon, iconRadius, iconColor, text)
    -- icon
    nvgFillColor(Color(0,0,0));
    nvgSvg(icon, x+0.92, y+0.46, iconRadius);
    nvgFillColor(iconColor);
    nvgSvg(icon, x, y, iconRadius);
    -- timer
    nvgFillColor(Color(0,0,0));
    nvgText(x+0.92, y+0.46+iconRadius/8, text);
    nvgFillColor(Color(255,255,255));
    nvgText(x, y+iconRadius/8, text)
end


function MgHUD_Buffs:draw()

    ------ Early out if HUD shouldn't be shown. ------
    if not shouldShowHUD() then return end
	if isRaceMode() then return end

    ------ GET PLAYER ------
    local player = getPlayer();


    ------ OPTIONS ------
    local carnage = {x=75, y=0, scale=1, color=Color(250,160,0)};
    local resist = {x=-75, y=0, scale=1, color=Color(30,30,256)};
    local mega = {x=0, y=0, scale=1};
    local friendFlag = {x=-250, y=0, scale=1};
    local enemyFlag = {x=250, y=0, scale=1};
    
    ------ HELPERS ------
    local iconRadius = 30;
    local fontSize = 2*iconRadius; -- 60
    local friendTeam = {num=player.team};
    friendTeam.color = teamColors[friendTeam.num];
    friendTeam.flagState = 0;
    local enemyTeam = {num=player.team%2+1};
    enemyTeam.color = teamColors[enemyTeam.num];
    enemyTeam.flagState = 0;
    carnage.timer = math.ceil(player.carnageTimer/1000);
    resist.timer = math.ceil(player.resistTimer/1000);

    ------ COLOR SHORTHAND ------
    local white = Color(255,255,255);
    local shadow = Color(48,48,48);
    local tshadow = Color(0,0,0,64);

    ------ TEXT FORMATTING ------
    nvgFontSize(fontSize);
    nvgFontFace("CodeProLC");
    nvgTextAlign(NVG_ALIGN_CENTER, NVG_ALIGN_MIDDLE);

    -- carnage
    if carnage.timer > 0 then
        drawBuff(carnage.x, carnage.y,
        "internal/ui/icons/carnage",
        carnage.scale*iconRadius, carnage.color,
        carnage.timer
        )
    end
    --

    -- resist
    if resist.timer > 0 then
        drawBuff(resist.x, resist.y,
        "internal/ui/icons/resist",
        resist.scale*iconRadius, resist.color,
        math.ceil(player.resistTimer/1000)
        )
    end
    --


--     -- enemy flag
--     if false then
--         nvgFillColor(shadow);
--         nvgSvg("internal/ui/icons/CTFflag", enemyFlag.x+2, enemyFlag.y+2, 30*1.3);
--         nvgFillColor(enemyTeam.color);
--         nvgSvg("internal/ui/icons/CTFflag", enemyFlag.x, enemyFlag.y, 30*1.3);
--     end
-- 
-- 
--     -- friend flag
--     if false then
--         nvgFillColor(shadow);
--         nvgSvg("internal/ui/icons/CTFflag",
--                 friendFlag.x+2, friendFlag.y+2, 30*1.3
--         );
--         nvgFillColor(friendTeam.color);
--         nvgSvg("internal/ui/icons/CTFflag",
--                 friendFlag.x, friendFlag.y, 30*1.3
--         );
--     end





end
